import request from '@/config/axios'

// 物品领用主 VO
export interface MaterialReceiveVO {
  id: number // 主键
  receiveCode: string // 领用号
  userId: number // 申请人id
  userName: string // 申请人
  deptId: number // 部门id
  deptName: string // 部门名称
  title: string // 申请标题
  remark: string // 备注
  status: number // 审批结果
  issueStatus: number // 发放状态：0-未发放，1-已发放
  processInstanceId: string // 流程实例的编号
}

// 物品领用主 API
export const MaterialReceiveApi = {
  // 查询物品领用主分页
  getMaterialReceivePage: async (params: any) => {
    return await request.get({ url: `/oa/material-receive/page`, params })
  },

  // 查询物品领用主详情
  getMaterialReceive: async (id: number) => {
    return await request.get({ url: `/oa/material-receive/get?id=` + id })
  },

  // 新增物品领用主
  createMaterialReceive: async (data: MaterialReceiveVO) => {
    return await request.post({ url: `/oa/material-receive/create`, data })
  },

  // 修改物品领用主
  updateMaterialReceive: async (data: MaterialReceiveVO) => {
    return await request.put({ url: `/oa/material-receive/update`, data })
  },

  // 删除物品领用主
  deleteMaterialReceive: async (id: number) => {
    return await request.delete({ url: `/oa/material-receive/delete?id=` + id })
  },

  // 导出物品领用主 Excel
  exportMaterialReceive: async (params) => {
    return await request.download({ url: `/oa/material-receive/export-excel`, params })
  },

  // 个人领用
  getOwnerMaterialReceivePage: async (params: any) => {
    return await request.get({ url: `/oa/material-receive/owner-page`, params })
  },


  // 分页获取本部门物品领用申请
  getDeptMaterialReceivePage: async (params: any) => {
    return await request.get({ url: `/oa/material-receive/dept-page`, params })
  },

  // 导出本部门物品领用申请 Excel
  exportDeptMaterialReceive: async (params: any) => {
    return await request.download({ url: `/oa/material-receive/dept-export-excel`, params })
  },

  // 发放物品
  issueMaterialReceive: async (id: number) => {
    return await request.put({ url: `/oa/material-receive/issue?id=` + id })
  },

  // 暂存物品领用单（草稿状态）
  saveDraft: async (data: MaterialReceiveVO) => {
    return await request.post({ url: `/oa/material-receive/save-draft`, data })
  },

  // 修改暂存的物品领用单
  updateDraft: async (data: MaterialReceiveVO) => {
    return await request.put({ url: `/oa/material-receive/update-draft`, data })
  },
}
